/**
 * Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.babble.subitem.controller;

import com.babble.subitem.dto.QueryCollectDTO;
import com.babble.subitem.service.ICollectService;
import com.babble.subitem.vo.CollectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springblade.common.exception.MsgException;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收藏表 控制器
 *
 * @author Blade
 * @since 2021-11-21
 */
@RestController
@RequestMapping("/collect")
@Api(value = "收藏表", tags = "收藏表接口")
@RequiredArgsConstructor
public class CollectController extends BladeController {
	private final ICollectService collectService;
	@ApiOperation(value = "添加收藏")
	@PostMapping("save")
	public R save(@RequestParam("id")String id) throws MsgException, MsgException {
		collectService.saveToCol(id);
		return R.data("添加成功");
	}
	@ApiOperation(value = "取消收藏")
	@PostMapping("del")
	public R del(@RequestParam("id")String id) throws MsgException, MsgException {
		collectService.delToCol(id);
		return R.data("取消成功");
	}

	@ApiOperation(value = "获取的分页收藏")
	@PostMapping("list")
	public R<List<CollectVO>> list(@RequestBody QueryCollectDTO queryCollectDTO) throws MsgException {
		List<CollectVO> list = collectService.listColVO(queryCollectDTO);
		return R.data(list);
	}
	@ApiOperation(value = "获取的自己分页收藏")
	@PostMapping("listById")
	public R<List<CollectVO>> listById(@RequestBody QueryCollectDTO queryCollectDTO) throws MsgException {
		List<CollectVO> list = collectService.listColVOById(queryCollectDTO);
		return R.data(list);
	}


}
